/*
  学习目标：组件逻辑复用三种方式-👍自定义hooks
  本质:
    1. 是一个函数， 必须以use开头
    2. 函数内部, 可以使用其它hooks, 用来封装逻辑
    3. 可以调用多次, 复用逻辑
*/

import React from 'react';
import { useMouse } from './useMouse';

export default function App() {
  return (
    <div>
      <Header />
      <Main />
      <Footer />
    </div>
  );
}

function Header() {
  const { mouse, handleMouseMove } = useMouse();
  return (
    <div onMouseMove={handleMouseMove}>
      <h1>
        x: {mouse.x} - y: {mouse.y}
      </h1>
    </div>
  );
}

function Main() {
  const { mouse, handleMouseMove } = useMouse();
  return (
    <div onMouseMove={handleMouseMove}>
      我是
      <h1>
        Main- x: {mouse.x} -y:{mouse.y}
      </h1>
    </div>
  );
}

function Footer() {
  const { mouse, handleMouseMove } = useMouse();
  return (
    <h1 onMouseMove={handleMouseMove}>
      Footer- x: {mouse.x} -y:{mouse.y}
    </h1>
  );
}
